package com.share.shareplatform.sharegoods.mq;

import com.rabbitmq.client.Channel;
import com.share.shareplatform.pojo.CommentOneLike;
import com.share.shareplatform.pojo.Repertory;
import com.share.shareplatform.pojo.exception.LogicException;
import com.share.shareplatform.sharegoods.dao.GoodsDao;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/*
*
* 库存删减任务
*
* */
@Component
public class RepertoryMessageConsume {

    @Autowired
    private GoodsDao goodsDao;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RabbitListener(queuesToDeclare = @Queue("repertory222"))
    public void consumer1(String message, Channel channel,@Header(AmqpHeaders.DELIVERY_TAG) long tag) throws IOException {

        List<Repertory> resolve = Repertory.resolve(message);
        int i = goodsDao.updateAllRepertory(resolve);
        channel.basicAck(tag,false);
        System.out.println("consumer2："+message);
    }


    @RabbitListener(bindings = @QueueBinding(value = @Queue(value = "repertory222", durable = "true", exclusive = "false"),
            exchange = @Exchange(value = "amq.direct")))
    public void consumer2(String message, Channel channel,@Header(AmqpHeaders.DELIVERY_TAG) long tag) throws IOException {

        List<Repertory> resolve = Repertory.resolve(message);
        int i = goodsDao.updateAllRepertory(resolve);
        //消息确认
        channel.basicAck(tag,false);
        System.out.println("consumer2："+message);
    }



}


